<?php
/*
 * IKPHP爱客网 安装程序 @copyright (c) 2012-3000 IKPHP All Rights Reserved @author 小麦
* @Email:ikphp@sina.cn
* @小麦  站内消息模型 2015年2月16日09:56:08
*/
class model_message extends model
{
	// 发送消息
	public function sendMessage($userid, $touserid, $title, $content) {
		if ($touserid && $content) {
			$data = array (
					'userid' => $userid,
					'touserid' => $touserid,
					'title' => $title,
					'content' => $content,
					'addtime' => time () 
			);
			if (! false == $this->create ( $data )) {
				$messageid = $this->add ();
			}
		
		}
		return $messageid>0 ? $messageid : 0;
	}
	//获取用户未读的消息数目
	public function getUnreadNum($uid){
		if($uid){
			$count = $this->where(array('touserid'=>$uid,'isread'=>0,'isinbox'=>0))->count();
			if($count>0){
				return $count;
			}
			return 0;
		}
		return 0;
	}
	
}